﻿using SimpleJson;
using System;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Networks.Handlers
{
    public class ConnectorHandler
    {
        public static void Execute(JsonObject data)
        {
            Debug.Log("ConnectorHandler.Execute");

            System.Object code = null;
            if (data.TryGetValue("code", out code))
            {
                int resultCode = Convert.ToInt32(code);

                if (resultCode == 200)
                {
                    Game.Instance.users = data;
                    SceneManager.LoadScene("Lobby");
                }
                else if (resultCode == 500)
                {
                    Debug.Log("Duplicate log in.");
                }
                else
                {
                    Debug.Log("Connection error.");
                }
            }
        }
    }
}